package com.bestcem.xm.qdes.controller.v2;

import cn.hutool.json.JSONObject;
import com.bestcem.xm.common.core.domain.web.XmResultJson;
import com.bestcem.xm.qdes.service.QdesQstructService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Slf4j
@Api(tags = "问卷编辑-V2")
@RestController
@RequiredArgsConstructor
@RequestMapping("/qdes/v2/qstructs")
public class QstructsV2Controller {

    private @NonNull QdesQstructService qdesQstructService;

    @ApiOperation(value = "设置评分接口")
    @PutMapping("/{id:[a-fA-F0-9]{24}}/scores")
    public XmResultJson<String> putScores(@PathVariable String id,
                                          @Validated @RequestBody JSONObject scoresJson) {
        return XmResultJson.success(qdesQstructService.putScores(id,scoresJson));
    }

    @ApiOperation(value = "获取评分接口")
    @GetMapping("/{id:[a-fA-F0-9]{24}}/scores/")
    public XmResultJson<Map> getScores(@PathVariable String id) {
        return XmResultJson.success(qdesQstructService.getScores(id));
    }

    @ApiOperation(value = "获取评分规则接口")
    @GetMapping("/{id:[a-fA-F0-9]{24}}/scoreconfig/")
    public XmResultJson<Map> getScoreConfig(@PathVariable String id) {
        return XmResultJson.success(qdesQstructService.getScoreConfig(id));
    }

    @ApiOperation(value = "设置评分规则接口")
    @PutMapping("/{id:[a-fA-F0-9]{24}}/scoreconfig")
    public XmResultJson<String> putScoreConfig(@PathVariable String id,
                                          @Validated @RequestBody JSONObject scoresJson) {
        return XmResultJson.success(qdesQstructService.putScoreConfig(id,scoresJson));
    }
}
